home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume29 / zsh2.2 / part01 next >
Encoding:
Text File  |  1992-05-13  |  49.1 KB  |  1,653 lines

  1. Newsgroups: comp.sources.misc
  2. From: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
  3. Subject:  v29i097:  zsh2.2 - The Z shell, Part01/17
  4. Message-ID: <csm-v29i097=zsh2.2.103215@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 6c35d02622176e5f8e7212cd57a60307
  6. Date: Wed, 13 May 1992 15:52:04 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
  10. Posting-number: Volume 29, Issue 97
  11. Archive-name: zsh2.2/part01
  12. Environment: BSD
  13. Supersedes: zsh2.1: Volume 24, Issue 1-19
  14.  
  15. #!/bin/sh
  16. # This is zsh2.2, a shell archive (produced by shar 3.49)
  17. # To extract the files from this archive, save it to a file, remove
  18. # everything above the "!/bin/sh" line above, and type "sh file_name".
  19. #
  20. # made 05/12/1992 04:14 UTC by pfalstad@phoenix
  21. # Source directory /n/homeserver/g/pfalstad
  22. #
  23. # existing files will NOT be overwritten unless -c is specified
  24. #
  25. # This is part 1 of a multipart archive                                    
  26. # do not concatenate these parts, unpack them in order with /bin/sh        
  27. #
  28. # This shar contains:
  29. # length  mode       name
  30. # ------ ---------- ------------------------------------------
  31. #   2684 -rw-r--r-- zsh2.2/FEATURES
  32. #    505 -rw-r--r-- zsh2.2/NOTES
  33. #  17490 -rw-r--r-- zsh2.2/README
  34. #  58603 -rw-r--r-- zsh2.2/doc/intro.txt
  35. #    247 -rw-r--r-- zsh2.2/dots/zlogin
  36. #   2291 -rw-r--r-- zsh2.2/dots/zshrc
  37. #    123 -rw-r--r-- zsh2.2/dots/zshenv
  38. #    104 -rwxr-xr-x zsh2.2/func/acx
  39. #    109 -rwxr-xr-x zsh2.2/func/cx
  40. #     97 -rwxr-xr-x zsh2.2/func/harden
  41. #     84 -rwxr-xr-x zsh2.2/func/mere
  42. #    412 -rwxr-xr-x zsh2.2/func/namedir
  43. #    194 -rwxr-xr-x zsh2.2/func/proto
  44. #     80 -rwxr-xr-x zsh2.2/func/randline
  45. #     29 -rwxr-xr-x zsh2.2/func/yp
  46. #     35 -rwxr-xr-x zsh2.2/func/yu
  47. # 112852 -rw-r--r-- zsh2.2/man/man1/zsh.1
  48. #    755 -rwxr-xr-x zsh2.2/scripts/aproto
  49. #    173 -rwxr-xr-x zsh2.2/scripts/fproto
  50. #   1137 -rw-r--r-- zsh2.2/scripts/ctoz
  51. #   2958 -rw-r--r-- zsh2.2/scripts/fooz
  52. #   3299 -rwxr-xr-x zsh2.2/scripts/c2z
  53. #   2736 -rwxr-xr-x zsh2.2/scripts/c2z.orig
  54. #  11626 -rwxr-xr-x zsh2.2/src/buildzsh
  55. #  61945 -rw-r--r-- zsh2.2/src/builtin.c
  56. #   4064 -rw-r--r-- zsh2.2/src/cond.c
  57. #  35818 -rw-r--r-- zsh2.2/src/exec.c
  58. #   1185 -rw-r--r-- zsh2.2/src/funcs.h
  59. #  24554 -rw-r--r-- zsh2.2/src/glob.c
  60. #  23511 -rw-r--r-- zsh2.2/src/hist.c
  61. #  11807 -rw-r--r-- zsh2.2/src/init.c
  62. #  16421 -rw-r--r-- zsh2.2/src/jobs.c
  63. #  15554 -rw-r--r-- zsh2.2/src/lex.c
  64. #   4752 -rw-r--r-- zsh2.2/src/loop.c
  65. #  10185 -rw-r--r-- zsh2.2/src/math.c
  66. #   4948 -rw-r--r-- zsh2.2/src/mem.c
  67. #  24577 -rw-r--r-- zsh2.2/src/params.c
  68. #  14912 -rw-r--r-- zsh2.2/src/subst.c
  69. #   6810 -rw-r--r-- zsh2.2/src/table.c
  70. #   8584 -rw-r--r-- zsh2.2/src/text.c
  71. #  32116 -rw-r--r-- zsh2.2/src/utils.c
  72. #   7149 -rw-r--r-- zsh2.2/src/watch.c
  73. #   8371 -rw-r--r-- zsh2.2/src/zle.h
  74. #  17212 -rw-r--r-- zsh2.2/src/zle_bindings.c
  75. #  14597 -rw-r--r-- zsh2.2/src/zle_main.c
  76. #  12058 -rw-r--r-- zsh2.2/src/zle_refresh.c
  77. #   4690 -rw-r--r-- zsh2.2/src/zle_utils.c
  78. #  31883 -rw-r--r-- zsh2.2/src/zsh.h
  79. #   4793 -rw-r--r-- zsh2.2/src/zle_vi.c
  80. #   1486 -rw-r--r-- zsh2.2/src/ztype.h
  81. #  26002 -rw-r--r-- zsh2.2/src/zle_tricky.c
  82. #   4239 -rw-r--r-- zsh2.2/src/builtin.pro
  83. #    235 -rw-r--r-- zsh2.2/src/cond.pro
  84. #   2306 -rw-r--r-- zsh2.2/src/exec.pro
  85. #   1511 -rw-r--r-- zsh2.2/src/glob.pro
  86. #   1989 -rw-r--r-- zsh2.2/src/hist.pro
  87. #    395 -rw-r--r-- zsh2.2/src/init.pro
  88. #    892 -rw-r--r-- zsh2.2/src/jobs.pro
  89. #    309 -rw-r--r-- zsh2.2/src/lex.pro
  90. #    206 -rw-r--r-- zsh2.2/src/loop.pro
  91. #    291 -rw-r--r-- zsh2.2/src/math.pro
  92. #    510 -rw-r--r-- zsh2.2/src/mem.pro
  93. #   3478 -rw-r--r-- zsh2.2/src/params.pro
  94. #    619 -rw-r--r-- zsh2.2/src/subst.pro
  95. #    941 -rw-r--r-- zsh2.2/src/table.pro
  96. #    371 -rw-r--r-- zsh2.2/src/text.pro
  97. #   3277 -rw-r--r-- zsh2.2/src/utils.pro
  98. #    371 -rw-r--r-- zsh2.2/src/watch.pro
  99. #      0 -rw-r--r-- zsh2.2/src/zle_bindings.pro
  100. #    686 -rw-r--r-- zsh2.2/src/zle_main.pro
  101. #    596 -rw-r--r-- zsh2.2/src/zle_refresh.pro
  102. #    761 -rw-r--r-- zsh2.2/src/zle_vi.pro
  103. #   1036 -rw-r--r-- zsh2.2/src/parse.pro
  104. #   1817 -rw-r--r-- zsh2.2/src/zle_tricky.pro
  105. #  18760 -rw-r--r-- zsh2.2/src/parse.c
  106. #    684 -rw-r--r-- zsh2.2/src/zle_utils.pro
  107. #   1429 -rw-r--r-- zsh2.2/src/signals.h.sample
  108. #   5181 -rw-r--r-- zsh2.2/src/zle_move.c
  109. #  14519 -rw-r--r-- zsh2.2/src/zle_misc.c
  110. #   6019 -rw-r--r-- zsh2.2/src/zle_word.c
  111. #  10080 -rw-r--r-- zsh2.2/src/zle_hist.c
  112. #   1119 -rw-r--r-- zsh2.2/src/zle_hist.pro
  113. #   1478 -rw-r--r-- zsh2.2/src/zle_misc.pro
  114. #    909 -rw-r--r-- zsh2.2/src/zle_move.pro
  115. #    733 -rw-r--r-- zsh2.2/src/zle_word.pro
  116. #   2607 -rw-r--r-- zsh2.2/src/config.h
  117. #   1322 -rw-r--r-- zsh2.2/src/signals.h
  118. #    921 -rw-r--r-- zsh2.2/src/Makefile
  119. #
  120. if test -r _shar_seq_.tmp; then
  121.     echo 'Must unpack archives in sequence!'
  122.     echo Please unpack part `cat _shar_seq_.tmp` next
  123.     exit 1
  124. fi
  125. # ============= zsh2.2/FEATURES ==============
  126. if test ! -d 'zsh2.2'; then
  127.     echo 'x - creating directory zsh2.2'
  128.     mkdir 'zsh2.2'
  129. fi
  130. if test -f 'zsh2.2/FEATURES' -a X"$1" != X"-c"; then
  131.     echo 'x - skipping zsh2.2/FEATURES (File already exists)'
  132.     rm -f _shar_wnt_.tmp
  133. else
  134. > _shar_wnt_.tmp
  135. echo 'x - extracting zsh2.2/FEATURES (Text)'
  136. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/FEATURES' &&
  137. Xvery close to ksh/sh grammar, with csh additions
  138. Xmost features of ksh, bash, and tcsh
  139. X75 builtins, 73 options, 144 key bindings
  140. Xshort for loops, ex: for i (*.c) echo $i
  141. Xselect
  142. Xshell functions
  143. Xconditional expressions (test builtin, [ ... ], and ksh-style [[ ... ]])
  144. Xglobal aliases (may be expanded anywhere on the line)
  145. Xdirectory stack access with =num
  146. Xprocess substitution (vi =(cmd) edits the output of cmd)
  147. Xgeneralized pipes (ls foo >>(cmd1) 2>>(cmd2) pipes stdout to cmd1
  148. X  and stderr to cmd2)
  149. Xarithmetic expressions
  150. Xadvanced globbing:
  151. X  ls **/file  searches recursively for "file" in subdirectories
  152. X  ls file<20->  matches file20, file30, file100, etc.
  153. X  ls *.(c|pro)  matches *.c and *.pro
  154. X  ls *(R)  matches only world-readable files
  155. X  ls *.c~lex.c  matches all .c files except lex.c
  156. Xnull command shorthands:
  157. X  "< file" is same as "more <file"
  158. X  "> file" is same as "cat >file"
  159. X  ">> file" is same as "cat >>file"
  160. Xksh-style coprocesses
  161. Xautomatic file stream teeing (ls >foo >bar puts output in two places)
  162. Xchpwd() function run every time you change directory (useful for
  163. X  updating the status line)
  164. Xjob control
  165. Xcsh-style history
  166. Xfull vi line editing, including "c2w" and "y$" and such things
  167. Xfull emacs line editing
  168. Xincremental history search
  169. Xmagic-space history
  170. Xspelling correction
  171. Xarray parameters
  172. X$HOSTTYPE, $LINENO, $RANDOM, $SECONDS, $cdpath, $COLUMNS, $fignore,
  173. X  $HISTCHARS, $mailpath
  174. Xwith autocd option, typing a directory name by itself is the same as
  175. X  typing "cd dirname"
  176. Xmenu completion: pressing TAB repeatedly cycles through the possible matches
  177. Xincremental path hashing
  178. Xautomatic process time reporting for commands that run over a certain limit
  179. Xfull tcsh-style prompt substitution
  180. Xutmp login/logout reporting
  181. Xwith histverify option, performing csh-style history expansions causes the
  182. X  input line to be brought up for editing instead of being executed
  183. Xwith sunkeyboardhack option, accidently typed trailing ` characters
  184. X  are removed from the input line (for those of you with Sun keyboards :-) )
  185. Xautoloaded functions (loaded from a file when they are first referenced)
  186. X"cd old new" replaces "old" with "new" in directory string
  187. Xgeneralized argument completion, including:
  188. X  - command name completion
  189. X  - filename and path completion
  190. X  - hostname completion
  191. X  - key binding completion
  192. X  - option completion
  193. X  - variable name completion
  194. X  - user-specified keyword completion
  195. Xprompt on right side of screen
  196. Xdirectory stacks
  197. Xhistory datestamps and execution time records
  198. Xcommand scheduling (like at(1), but in the shell's context)
  199. Xtty mode freezing
  200. Xup to 9 startup files (but you only need 1 or 2)
  201. X8-bit clean
  202. Xwhich -a cmd lists all occurences of "cmd" in the path
  203. SHAR_EOF
  204. chmod 0644 zsh2.2/FEATURES ||
  205. echo 'restore of zsh2.2/FEATURES failed'
  206. Wc_c="`wc -c < 'zsh2.2/FEATURES'`"
  207. test 2684 -eq "$Wc_c" ||
  208.     echo 'zsh2.2/FEATURES: original size 2684, current size' "$Wc_c"
  209. rm -f _shar_wnt_.tmp
  210. fi
  211. # ============= zsh2.2/NOTES ==============
  212. if test -f 'zsh2.2/NOTES' -a X"$1" != X"-c"; then
  213.     echo 'x - skipping zsh2.2/NOTES (File already exists)'
  214.     rm -f _shar_wnt_.tmp
  215. else
  216. > _shar_wnt_.tmp
  217. echo 'x - extracting zsh2.2/NOTES (Text)'
  218. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/NOTES' &&
  219. XImportant notes:
  220. X
  221. X1. Stuff like "ls *.sdofij 2>/dev/null" to suppress error messages
  222. X   produced by the shell don't work anymore.  Filename generation is
  223. X   done BEFORE redirection.  To avoid the error message, use the
  224. X   nonomatch option, or do "( ls *.sdofij ) 2>/dev/null".
  225. X
  226. X2. History substitution is no longer done inside startup files.  If you
  227. X   have sequences like \! or !" in your startup files, they will break.
  228. X   (Especially !").  So check for those; remove the !", and change the
  229. X   \! to !.
  230. SHAR_EOF
  231. chmod 0644 zsh2.2/NOTES ||
  232. echo 'restore of zsh2.2/NOTES failed'
  233. Wc_c="`wc -c < 'zsh2.2/NOTES'`"
  234. test 505 -eq "$Wc_c" ||
  235.     echo 'zsh2.2/NOTES: original size 505, current size' "$Wc_c"
  236. rm -f _shar_wnt_.tmp
  237. fi
  238. # ============= zsh2.2/README ==============
  239. if test -f 'zsh2.2/README' -a X"$1" != X"-c"; then
  240.     echo 'x - skipping zsh2.2/README (File already exists)'
  241.     rm -f _shar_wnt_.tmp
  242. else
  243. > _shar_wnt_.tmp
  244. echo 'x - extracting zsh2.2/README (Text)'
  245. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/README' &&
  246. XYou have permission to copy the zsh distribution in whole or in part
  247. Xas long as you don't try to make money off of it, or pretend that you
  248. Xwrote it.
  249. X
  250. XThis is zsh 2.2.0.
  251. X
  252. XTo get this shell running, cd into the src directory and type
  253. X"buildzsh".  I tested it on the following machines, where it compiled
  254. Xjust by running this script:
  255. X
  256. XSun SPARCServer 4/690 running SunOS 4.1.2
  257. XNeXTstation running Mach 2.0
  258. XDECStation-5000 running ULTRIX 4.2
  259. XIris 4D/20 running IRIX 4.0.1
  260. XHP 9000/834 running HP-UX 7.00
  261. XIBM RS6000 running AIX 3.2
  262. X(rumored to work on a Pyramid)
  263. X
  264. XIn general, the more BSD-like your system, the more likely it will work.
  265. X
  266. XTabstops are 3 spaces.  If you're going to look at my code, run it
  267. Xthough "expand -3" first, or set your tab stops to the same as mine.
  268. X
  269. XThere is a zsh mailing list, "zsh-list@cs.uow.edu.au".  To have yourself
  270. Xadded to the list, send a request to "zsh-request@cs.uow.edu.au".
  271. X
  272. XThe author can be reached via email to one of the following addresses:
  273. X"pfalstad@phoenix.princeton.edu", "pfalstad@cs.ucsd.edu", "pf@ttisms.com",
  274. X"pf@gnu.ai.mit.edu".
  275. X
  276. XThanks to the following people for help, ideas, accounts, comments,
  277. Xpatches, etc.:
  278. XCharles Hannum
  279. XDavid Dobkin
  280. XJim Mattson
  281. XCarlos Carvalho
  282. XBart Schaefer
  283. XPeter Gray
  284. XPure Software, Inc.
  285. XChris P. Ross
  286. XGary Oberbrunner
  287. XJonathan Hardwick
  288. XJohn Navarra
  289. XMichael Lamoureux
  290. XRick Lyons
  291. XDuncan Sinclair
  292. XMark R. Rubin
  293. XJohn Guthrie
  294. XJames Bonfield
  295. XChris Moore
  296. XThomas Winder
  297. XDavid J. MacKenzie
  298. XCharles Rendleman
  299. XRichard Ohnemus
  300. XNik Gervae
  301. XGottfried Necker
  302. XGoran Larsson
  303. XPaul E. Maisano
  304. XNorbert Kiesel
  305. XJosh Diamond
  306. XBill Miskovetz
  307. XPeter Moore
  308. XGeoff Wing
  309. XKent Dickey
  310. XJean-Jacques Moreau
  311. XMichael Brown
  312. XBruce Anderson
  313. XStephen Dum
  314. XLars E. Thon
  315. XMichael Brennan
  316. XXev Gittler
  317. XJarkko Hietaniemi
  318. XZbigniew J Tyrlik
  319. XPierre Racz
  320. XRick Ohnemus
  321. XRichard Dean
  322. XGary D. Kline
  323. XRobert A. Fabian
  324. XByron Rakitzis
  325. XDan Bernstein
  326. XJonathan Kamens
  327. XVincent Granet
  328. XDavid Wilson
  329. XGreg Noel
  330. XPaul Lew
  331. XDan Esbensen
  332. XKartik Subbarao
  333. XRoss Bunker
  334. XMichael Marucheck
  335. XChristopher Pirazzi
  336. XSteve Giovanetti
  337. XKennedy Lemke
  338. XEmin Gun Sirer
  339. XKazuo Itoh
  340. Xlots of other people, I'm sure
  341. X
  342. XModification history:
  343. X
  344. X2.2.0-2.1.0:
  345. Xo should be faster in general
  346. Xo fewer compilation warnings
  347. Xo SPROMPT now uses %R instead of %s for the incorrect string
  348. Xo no longer tries to create FIFOs on NeXTs (thereby causing a panic)
  349. Xo now gets usernames from NIS on irises without crashing (SGI's getpwnam()
  350. X  called my strdup(), the pricks.  Took me forever to find that.  :-) )
  351. Xo fewer 7-bit assumptions
  352. Xo which/whence/type have new options:
  353. X  -a = all (find all occurences of command in path)
  354. X  -c = csh-style which (default for "which" command)
  355. Xo error message for cd str1 str2 is fixed
  356. Xo relative paths (including .) in cdpath now work
  357. Xo exclusion patterns in glob: ls *.c~lex.c prints all .c files but lex.c
  358. Xo bug with command substitution in chpwd fixed (buffers flushed twice)
  359. Xo relative paths in $path now work
  360. Xo "kill -9 -FOO" no longer kills shell
  361. Xo new options to history/fc:
  362. X    -d = prints date commands were entered
  363. X    -D = prints running time of commands
  364. Xo "history <num>" prints all commands SINCE <num> as well
  365. Xo history stored differently - should be more efficient
  366. Xo bg'ing a suspended zsh no longer causes problems
  367. Xo "set" no longer prints ONLY exported params (duh)
  368. Xo functions +t now allowed
  369. Xo redirection is done AFTER filename generation
  370. Xo print changes:
  371. X  o print -u# prints to fd #
  372. X  o print -p prints to coproc
  373. X  o -D and -P perform \ substitution first
  374. X  o print -0 changed to print -N
  375. Xo read changes:
  376. X  o read -u# reads from fd #
  377. X  o read -p reads from coproc
  378. X  o read -z waits for input if nothing on buffer stack
  379. X  o no longer reads from fd 0 if shell is getting input from there
  380. X  o echo -n foo | read x  now works
  381. Xo getopts is now POSIX conformant
  382. Xo compctl builtin added, replacing hostcmds, foocmds, etc.  Controls
  383. X  completion of various commands in zle.
  384. X  format: compctl -options cmdnams ...
  385. X  options tell where to get possible matches from, and include:
  386. X     -c = command names
  387. X     -f = filenames
  388. X     -h = hostnames ($hosts)
  389. X     -o = options
  390. X     -v = vars
  391. X     -b = bindings
  392. X     -k name = elements of $name array
  393. X  Any number of these options may be used together.
  394. X  In addition, compctl -C -options will set the default completion
  395. X  names when in command position (by default -c), and compctl -D -options
  396. X  will set the default completion names used after unrecognized commands
  397. X  or after redirections (by default -f).
  398. Xo foo && bar || fuu now works
  399. Xo ttyctl builtin added
  400. X  ttyctl -f freezes the tty.  no changes made to the tty settings by
  401. X     external programs will be honored when this command is in effect.
  402. X  ttyctl -u unfreezes the tty.
  403. X  typically, "ttyctl -f" would be used in a zlogin or zshrc script after
  404. X  "stty" has been called to set up the terminal.
  405. Xo [[ -e file ]] is now equivalent to [[ -a file ]]
  406. Xo [[ -h file ]] is now equivalent to [[ -L file ]]
  407. Xo the path is now hashed incrementally.
  408. X  o if the HASHCMDS option is unset, path hashing is not done at all.
  409. X  o if the HASHCMDS option is set but HASHDIRS is unset, commands are placed
  410. X     in the hash table when first executed.
  411. X  o if the HASHCMDS and HASHDIRS options are both set, commands are placed
  412. X     in the hash table when first executed, along with all commands in
  413. X     the directory that command was found in (and all directories earlier
  414. X     in the path).  This is the default situation.
  415. Xo "for i (*.c) do /bin/echo $i ; done | more" no longer hangs
  416. Xo coprocesses now work properly
  417. Xo READNULLCMD is now used instead of NULLCMD for "< file"
  418. Xo POSTEDIT is printed whenever the editor exits
  419. Xo rm path/path/* is now reported by checkrmall()
  420. Xo cmd >&- works
  421. Xo cmd >>! file works
  422. Xo time cmd no longer forks an extra process
  423. Xo setopt printexitvalue ; echo `false` no longer prints anything
  424. Xo here documents work inside eval, etc.
  425. Xo $(...) works inside here documents
  426. Xo "time" by itself prints the shell timings
  427. Xo locals in precmd() or chpwd() work
  428. Xo new glob qualifiers
  429. X  o pat(M) sets markdirs, pat(^M) unsets it
  430. X  o pat(N) sets nullglob, ...
  431. X  o pat(D) sets globdots, ...
  432. Xo ls * only sorts numeric filenames specially if NUMERICGLOBSORT is set
  433. Xo setopt braceccl lets "echo {a-zA-Z}" work
  434. Xo new options: pushdignoredups nohistbeep overstrike
  435. Xo ls **/file is now equivalent to ls ****/file
  436. Xo !'s in history are now escaped when you return to them
  437. Xo history substitution is not done in script files
  438. Xo echo $(!-2) works
  439. Xo histverify and correct 'e' no longer put the edit line in the history
  440. Xo the :x, :q, and :gs modifiers work properly now
  441. Xo zsh -c 'ls =(ls)' no longer hangs
  442. Xo VSWTCH is now set to ^Z on the irises
  443. Xo zsh & no longer causes havoc
  444. Xo USERNAME and LOGNAME are kept separate
  445. Xo $manpath has been added for easy access to the $MANPATH components
  446. Xo zsh now realizes if it is running under emacs, and resigns itself to
  447. X  the fact rather than panicking
  448. Xo SIGQUIT is ignored in the PRODUCTION version of zsh, and kills the shell
  449. X  in the DEBUG version, rather than vice versa.
  450. Xo GLOBALZSHENV has been added, and GLOBALZPROFILE is sourced in the
  451. X  proper place
  452. Xo "kill %" no longer causes the prompt to be printed 3 times if notify
  453. X  is set on a NeXT
  454. Xo REPORTTIME has been added; if a job runs longer than this many seconds,
  455. X  timing statistics are reported
  456. Xo timing statistics now include a job name (%J)
  457. Xo no longer talks about SIGHUPed jobs if the kill failed
  458. Xo no longer talks about running jobs which don't exist if you do eval exit
  459. X  or if you have notify unset
  460. Xo foo=bar comman[tab], for/select/foreach i (*.c[tab] both work
  461. Xo [base]num inside $[...] works
  462. Xo foo=pat(n|ern) works
  463. Xo cd - prints the new directory
  464. Xo l[tab] works if l is an alias
  465. Xo select foo ; ... works (in $argv is assumed)
  466. Xo select reads from the right input
  467. Xo math identifiers can now contain numbers and _'s.
  468. Xo lots of serious memory heap trashing and leaks fixed
  469. Xo echo $HOME[*] no longer crashes the shell
  470. Xo SIGWINCH now changes LINES and COLUMNS in the environment
  471. Xo typeset +r TTY; TTY=foo no longer causes problems
  472. Xo ~ substitution is no longer done in FIGNORE
  473. Xo assignment to SECONDS works
  474. Xo "else if" is no longer a synonym for "elif" <thud>
  475. Xo lots of problems with null lists in flow constructs fixed
  476. Xo no correction done for >file
  477. Xo echo ${foo%bar is no longer weird
  478. Xo modifying array substitutions works
  479. Xo ^O can be bound to something
  480. Xo command substitution in signal handlers no longer causes problems
  481. Xo spelling correction is better ($PAHT is corrected), and SPROMPT
  482. X  allows all the regular PROMPT escapes
  483. Xo new prompt escape sequence: %D{...} formats ... part using strftime
  484. Xo shell input no longer butchered using IFS
  485. Xo vi cmd mode has 's' bound to visubstitute, as it should be
  486. Xo you can use ^XS and ^XR in i-search mode
  487. Xo bindings to ^Z and ^@ work now on the irises
  488. Xo ^V{^S,^Q,^Z,etc} now works on sgttyb victims
  489. Xo nopromptclobber changed to nopromptcr
  490. Xo vi 'u' undo works a little better (?)
  491. Xo ESC-key bindings aren't screwed up if VISUAL is set to vi
  492. Xo newline in prompt now works reliably
  493. Xo vi change and delete work with forward-word/search, etc.
  494. Xo somewhat suboptimal screen refresh on irises fixed (several seconds
  495. X  per character inserted when TERM=xterm??)
  496. Xo select list printing slightly different
  497. Xo magic-space's handling of hatchars "fixed"
  498. X
  499. X0.03-1.0:
  500. X    - "..../" is now "****/".  I know this isn't backward compatible,
  501. X      but I had no choice; the string "..../" was unquotable.
  502. X    - parser was rewritten and improved
  503. X    - completion was improved, several bugs fixed (including
  504. X      the "$([tab]" bug)
  505. X    - vi mode editing is improved
  506. X    - the value of PWD and OLDPWD in the environment now change
  507. X    - the PROMPT formatting strings %W and %D now print the month
  508. X      correctly
  509. X    - >&2 echo "error message" no longer prints "bad file number"
  510. X    - ${foo%pat} no longer alters the value of foo
  511. X    - $_ works
  512. X    - ALL_EXPORT no longer causes let statements to crash the shell
  513. X    - continue works
  514. X    - echo $MAIL no longer dumps core if MAIL is null
  515. X    - the new tty driver is selected by default
  516. X    - the s modifier no longer complains if it can't find the string
  517. X      to substitute
  518. X    - list-choices no longer fignores files
  519. X    - cd is now smarter about symlinks
  520. X    - negative subscripts other than -1 now work
  521. X    - $(<filename) works better if filename contains $, ~, or =
  522. X    - rehash no longer wastes memory
  523. X    - with name=value assignments, name is checked to see if it is
  524. X      a valid identifier
  525. X    - !1; !2 no longer eats the semicolon
  526. X    - $foo:h never returns the empty string if foo starts with /
  527. X    - select crashed with some compilers
  528. X    - problems with aliases in <(...) constructs have been fixed
  529. X    - links pointing to nowhere are denoted with an '&' in listtypes
  530. X    - negative arguments are supported
  531. X    - the shell does not screw around with the tty so much
  532. X    - lots of other stuff
  533. X
  534. X0.02-0.03:
  535. X    - two stupid bugs that were introduced in the last patch were fixed:
  536. X      - multiple command substitution on a line failed
  537. X      - a file descriptor leak caused the shell to crash after a while
  538. X    - added 'An Introduction to the Z Shell'
  539. X    - behaves properly when the tty session dies suddenly
  540. X    - had a serious memory leak on some systems
  541. X    - the test and [ builtins have been added, although [[...]]
  542. X      is more efficient
  543. X    - in your prompt, %m2 now prints foo.bar, %m3 prints foo.bar.com, etc.
  544. X    - the -D and -P options to print have been added
  545. X    - the NULLCMD and ZDOTDIR parameters have been added
  546. X    - ${*:-foo} works
  547. X    - "$@" and "$arr[@]" work like ksh
  548. X    - .zprofile is sourced before .zshrc in login shells
  549. X    - the CSHJUNKIEQUOTES and PUSHDMINUS options have been added
  550. X    - REAL_TTY compilation switch added
  551. X    - aliases beginning with a space cause the history line to be junked
  552. X      if HISTIGNORESPACE is set
  553. X    - echo prints bad options instead of complaining about them
  554. X    - "set -o" no longer dumps core
  555. X    - "alias a=alias; date >a" no longer creates a file called "alias"
  556. X    - "function foo() \n { date }" is now legal (the () and the newline
  557. X      are allowed)
  558. X    - nested brace expressions work properly
  559. X    - disabled commands stay disabled after a rehash (or after the shell
  560. X      finishes sourcing your .zshrc)
  561. X    - corrected aliases work
  562. X    - executables in the currect directory are now completed
  563. X    - in "case foo", "foo" is not interpreted as a directory name with autocd
  564. X    - aliases were not always interpreted properly after a completion
  565. X    - bindkey '^?' didn't work
  566. X    - echo ${HOST:-{bar}} didn't work
  567. X    - editor update is more efficient in some cases
  568. X    - menucomplete works even better
  569. X    - assign to an array element "foo[1]=bar" didn't always work
  570. X    - doesn't print directories like "~tmp" if HOME=/
  571. X    - quotes in case statement patterns caused problems
  572. X    - pressing ^C right after typing "fc" caused the editor to share
  573. X      the tty with the shell
  574. X    - echo $(echo 2) produced no output, but echo $(echo x) worked fine (weird)
  575. X
  576. X0.01-0.02:
  577. X    - added script to convert most csh aliases to zsh aliases or functions
  578. X    - fc -l (history) now appears in the history itself; HISTNOSTORE
  579. X      option added to get old behavior
  580. X    - the POSIX process group race has been fixed; so 'w | more' should
  581. X      no longer hang
  582. X    - FCEDIT added, to match the documentation
  583. X    - %{...%} in the prompt added
  584. X    - execute-named-cmd and execute-last-named-cmd bindings added
  585. X    - sources ~/.zshenv in all shells, even if not interactive, unless
  586. X      -f is given
  587. X    - ^ and # are no longer `magic' by default; use EXTENDEDGLOB option
  588. X      to use them
  589. X    - now checks for tty sanity before each command
  590. X    - if the right side of a variable assignment expands to more than
  591. X      one word, array assignment is assumed; so foo=*.c now works
  592. X    - ~foo is no longer expanded in completion
  593. X    - select now works even if the argument list is not sorted
  594. X    - menucompletebeep option added
  595. X    - emacs mode is now 8-bit clean by default; use bindkey -em
  596. X      to get your meta key back
  597. X    - fc -R, fc -W added
  598. X    - nocorrect added
  599. X    - lines from history file are now split into words at spaces
  600. X    - glob-complete, accept-and-menu-complete,
  601. X      beginning-of-line-hist, end-of-line-hist bindings added
  602. X    - insert-last-word bound to M-. in emacs mode by default; now moves
  603. X      back through the history if run repeatedly
  604. X    - J and K now bound to history search in vi mode
  605. X    - delete-char no longer core dumps on an empty line
  606. X    - menu-complete works better
  607. X    - the editor checks the settings of VISUAL and EDITOR to set
  608. X      default bindings
  609. X    - using [[ ... ]] expressions on a symbolic link works as expected
  610. X    - various problems with globbing were fixed
  611. X    - xx is now the same as !! if HISTCHARS=x
  612. X    - added config.h entry for compilers that don't know about void *
  613. X    - lexical analysis made more efficient
  614. X    - "if echo $? ; then : ; fi" no longer always prints 0
  615. X    - removed all enums, '\x7f's from code
  616. X    - in "case foo in bar) xxx ;; esac", foo and bar are no longer subject
  617. X      to command alias expansion
  618. X    - works on platforms where toupper('A') != 'A'
  619. X    - \e sequence added to echo
  620. X    - + options now work with set
  621. X    - AUTORESUME and AUTOCD work better
  622. X    - getopts works better (?)
  623. X    - spell checking works better
  624. X    - "let 2+3=" no longer crashes the shell
  625. X    - "foo=bar; echo ${=foo}" no longer crashes the shell
  626. X    - "zsh -c" or "zsh -o" no longer causes a core dump
  627. X    - "unset MAIL; echo $MAIL" no longer causes a core dump
  628. X    - "(xterm&xterm&)&" no longer causes a core dump
  629. X    - "echo $HOM[tab]" beeps instead of deleting "$HOM"
  630. X    - incremental history search works better
  631. X    - the pwd of a fg'd job is now printed _before_ resuming it
  632. X    - rv=`echo -n foo` no longer puts garbage in $rv
  633. X    - "=1/*" now works as expected
  634. X    - ^Z can now be bound to something
  635. X    - the STTY parameter and the builtin builtin are now documented
  636. X    - IFS=x; foo=`echo foo` no longer puts a newline in $foo
  637. X    - $status added for csh compatibility
  638. X    - arrays are automatically expanded if you say 'foo[1234]=x'
  639. X    - shell now ignores SIGQUIT (it was commented out before :-)
  640. X    - the times builtin works on systems where times() returns > 0
  641. X    - no longer hangs the terminal if you ^S before flow control
  642. X      is turned off
  643. X    - "date ; read foo" now works in interactive shells
  644. X    - <<-foo is now parsed as <<- foo, not << -foo
  645. X    - fixed various errors in the documentation
  646. X
  647. X0.00-0.01:
  648. X    - %M and %m now work as documented.
  649. X    - bad things no longer happen if COLUMNS is set to 0
  650. X    - SH_WORD_SPLIT and ${=foo} now work
  651. X    - the default value of WORDCHARS includes more characters
  652. X    - if the cursor is at the end of the line, vi-cmd-mode
  653. X      moves it back one position.
  654. X    - delete-char now acts more like x in vi.
  655. X    - a "prompt" parameter has been added, which is equivalent to
  656. X      PROMPT and PS1.
  657. X    - zsh no longer expands symbolic links.  The CHASELINKS option
  658. X      has been provided to get the old behavior.
  659. X    - history searches ignore lines that are the same as the line
  660. X      in the buffer.
  661. X    - you can get a literal ! in your prompt now with \!.
  662. X    - -z, -n, and != in [[ ... ]] expressions work.
  663. X    - the shell no longer hangs when inputting "[[ ]\n"
  664. X    - the "menu-complete" and "menu-expand-or-complete" bindings have
  665. X      been added.
  666. X    - menu-complete no longer beeps.
  667. X    - reverse-menu-complete no longer dumps core if it gets called before
  668. X      a normal completion.
  669. X    - typeahead lines are no longer thrown away on machines with sgttyb.
  670. X    - !foo no longer matches lines with 'foo' in them (not at the beginning)
  671. X    - kill -9 % no longer kills the shell
  672. X    - no longer sources .zshrc from shell scripts or with -c
  673. X    - no longer needs limits.h, strtol
  674. X    - exporting HOSTTYPE, etc. works
  675. X    - fixed serious bugs related to . in path
  676. X    - numbers in weird bases now work
  677. X
  678. XKnown Bugs
  679. X    - terminal acts weird under OpenWindows cmdtool
  680. X    - xterm run in background inherits bad terminal modes
  681. X
  682. SHAR_EOF
  683. chmod 0644 zsh2.2/README ||
  684. echo 'restore of zsh2.2/README failed'
  685. Wc_c="`wc -c < 'zsh2.2/README'`"
  686. test 17490 -eq "$Wc_c" ||
  687.     echo 'zsh2.2/README: original size 17490, current size' "$Wc_c"
  688. rm -f _shar_wnt_.tmp
  689. fi
  690. # ============= zsh2.2/doc/intro.txt ==============
  691. if test ! -d 'zsh2.2/doc'; then
  692.     echo 'x - creating directory zsh2.2/doc'
  693.     mkdir 'zsh2.2/doc'
  694. fi
  695. if test -f 'zsh2.2/doc/intro.txt' -a X"$1" != X"-c"; then
  696.     echo 'x - skipping zsh2.2/doc/intro.txt (File already exists)'
  697.     rm -f _shar_wnt_.tmp
  698. else
  699. > _shar_wnt_.tmp
  700. echo 'x - extracting zsh2.2/doc/intro.txt (Text)'
  701. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/doc/intro.txt' &&
  702. X
  703. X
  704. X
  705. X
  706. X
  707. X
  708. X               An Introduction to the Z Shell
  709. X
  710. X
  711. X                        Paul Falstad
  712. X               pfalstad@phoenix.princeton.edu
  713. X
  714. X
  715. X
  716. X
  717. X
  718. X
  719. Xzsh is a shell designed for interactive use, although it  is
  720. Xalso  a  powerful  scripting  language.   Many of the useful
  721. Xfeatures of bash, ksh, and tcsh were incorporated into  zsh;
  722. Xmany  original  features  were added.  This document details
  723. Xsome of the  unique  features  of  zsh.   It  assumes  basic
  724. Xknowledge of the standard UNIX shells; the intent is to show
  725. Xa reader already familiar with one of the other major shells
  726. Xwhat  makes zsh more useful or more powerful.  This document
  727. Xis not at all comprehensive; read the  manual  entry  for  a
  728. Xdescription  of  the  shell  that  is  complete and concise,
  729. Xalthough somewhat overwhelming and devoid of examples.
  730. X
  731. XFilename Generation
  732. X
  733. XOtherwise known as globbing, filename  generation  is  quite
  734. Xextensive in zsh.  Of course, it has all the basics:
  735. X
  736. X% ls
  737. XMakefile   file.pro   foo.o      main.o     q.c        run234     stuff
  738. Xbar.o      foo        link       morestuff  run123     run240     sub
  739. Xfile.h     foo.c      main.h     pipe       run2       run303
  740. X% ls *.c
  741. Xfoo.c  q.c
  742. X% ls *.[co]
  743. Xbar.o   foo.c   foo.o   main.o  q.c
  744. X% ls foo.?
  745. Xfoo.c  foo.o
  746. X% ls *.[^c]
  747. Xbar.o   file.h  foo.o   main.h  main.o
  748. X% ls *.[^oh]
  749. Xfoo.c  q.c
  750. X
  751. X
  752. XAlso, if the EXTENDEDGLOB option is set, some  new  features
  753. Xare  activated.   For  example,  the ^ character negates the
  754. Xpattern following it:
  755. X
  756. X
  757. X
  758. X
  759. X
  760. X
  761. X
  762. X
  763. X
  764. X
  765. X
  766. X
  767. X
  768. X
  769. X
  770. X                           - 2 -
  771. X
  772. X% setopt extendedglob
  773. X% ls -d ^*.c
  774. XMakefile   file.pro   link       morestuff  run2       run303
  775. Xbar.o      foo        main.h     pipe       run234     stuff
  776. Xfile.h     foo.o      main.o     run123     run240     sub
  777. X% ls -d ^*.*
  778. XMakefile   link       pipe       run2       run240     stuff
  779. Xfoo        morestuff  run123     run234     run303     sub
  780. X% ls -d ^Makefile
  781. Xbar.o      foo        link       morestuff  run123     run240     sub
  782. Xfile.h     foo.c      main.h     pipe       run2       run303
  783. Xfile.pro   foo.o      main.o     q.c        run234     stuff
  784. X% ls -d *.^c
  785. X.rhosts   bar.o     file.h    file.pro  foo.o     main.h    main.o
  786. X
  787. X
  788. XAn expression of the form <x-y> matches a range of integers:
  789. X
  790. X% ls run<200-300>
  791. Xrun234  run240
  792. X% ls run<300-400>
  793. Xrun303
  794. X% ls run<-200>
  795. Xrun123  run2
  796. X% ls run<300->
  797. Xrun303
  798. X% ls run<>
  799. Xrun123  run2    run234  run240  run303
  800. X
  801. X
  802. XGrouping is possible:
  803. X
  804. X% ls (foo|bar).*
  805. Xbar.o  foo.c  foo.o
  806. X% ls *.(c|o|pro)
  807. Xbar.o     file.pro  foo.c     foo.o     main.o    q.c
  808. X
  809. X
  810. XAlso, the string ****/ forces a  recursive  search  of  sub-
  811. Xdirectories:
  812. X
  813. X
  814. X
  815. X
  816. X
  817. X
  818. X
  819. X
  820. X
  821. X
  822. X
  823. X
  824. X
  825. X
  826. X
  827. X
  828. X
  829. X
  830. X
  831. X
  832. X
  833. X
  834. X
  835. X
  836. X                           - 3 -
  837. X
  838. X% ls -R
  839. XMakefile   file.pro   foo.o      main.o     q.c        run234     stuff
  840. Xbar.o      foo        link       morestuff  run123     run240     sub
  841. Xfile.h     foo.c      main.h     pipe       run2       run303
  842. X
  843. Xmorestuff:
  844. X
  845. Xstuff:
  846. Xfile  xxx   yyy
  847. X
  848. Xstuff/xxx:
  849. Xfoobar
  850. X
  851. Xstuff/yyy:
  852. Xfrobar
  853. X% ls ****/*bar
  854. Xstuff/xxx/foobar  stuff/yyy/frobar
  855. X% ls ****/f*
  856. Xfile.h            foo               foo.o             stuff/xxx/foobar
  857. Xfile.pro          foo.c             stuff/file        stuff/yyy/frobar
  858. X% ls *bar*
  859. Xbar.o
  860. X% ls ****/*bar*
  861. Xbar.o             stuff/xxx/foobar  stuff/yyy/frobar
  862. X% ls stuff/****/*bar*
  863. Xstuff/xxx/foobar  stuff/yyy/frobar
  864. X
  865. X
  866. X
  867. XIt is possible to exclude certain files  from  the  patterns
  868. Xusing  the  ~  character.   A  pattern of the form *.c~bar.c
  869. Xlists all files matching *.c, except for the file bar.c.
  870. X
  871. X% ls *.c
  872. Xfoo.c    foob.c    bar.c
  873. X% ls *.c~bar.c
  874. Xfoo.c    foob.c
  875. X% ls *.c~f*
  876. Xbar.c
  877. X
  878. X
  879. X
  880. XOne can add a number of qualifiers to  the  end  of  any  of
  881. Xthese  patterns,  to restrict matches to certain file types.
  882. XA qualified pattern is of the form
  883. X
  884. X        pattern(...)
  885. X
  886. X
  887. Xwith single-letter qualifiers inside the parentheses.
  888. X
  889. X
  890. X
  891. X
  892. X
  893. X
  894. X
  895. X
  896. X
  897. X
  898. X
  899. X
  900. X
  901. X
  902. X                           - 4 -
  903. X
  904. X% alias l='ls -dF'
  905. X% l *
  906. XMakefile    foo*        main.h      q.c         run240
  907. Xbar.o       foo.c       main.o      run123      run303
  908. Xfile.h      foo.o       morestuff/  run2        stuff/
  909. Xfile.pro    link@       pipe        run234      sub
  910. X% l *(/)
  911. Xmorestuff/  stuff/
  912. X% l *(@)
  913. Xlink@
  914. X% l *(*)
  915. Xfoo*        link@       morestuff/  stuff/
  916. X% l *(x)
  917. Xfoo*        link@       morestuff/  stuff/
  918. X% l *(X)
  919. Xfoo*        link@       morestuff/  stuff/
  920. X% l *(R)
  921. Xbar.o       foo*        link@       morestuff/  run123      run240
  922. Xfile.h      foo.c       main.h      pipe        run2        run303
  923. Xfile.pro    foo.o       main.o      q.c         run234      stuff/
  924. X
  925. X
  926. XNote that  *(x)  and  *(*)  both  match  executables.   *(X)
  927. Xmatches  files  executable  by  others,  as opposed to *(x),
  928. Xwhich matches files executable by the owner.  *(R) and  *(r)
  929. Xmatch  readable files; *(W) and *(w), which checks for writ-
  930. Xable files.  *(W) is especially important, since  it  checks
  931. Xfor world-writable files:
  932. X
  933. X% l *(w)
  934. Xbar.o       foo*        link@       morestuff/  run123      run240
  935. Xfile.h      foo.c       main.h      pipe        run2        run303
  936. Xfile.pro    foo.o       main.o      q.c         run234      stuff/
  937. X% l *(W)
  938. Xlink@   run240
  939. X% l -l link run240
  940. Xlrwxrwxrwx  1 pfalstad       10 May 23 18:12 link -> /bin/false*
  941. X-rw-rw-rw-  1 pfalstad        0 May 23 18:12 run240
  942. X
  943. X
  944. XYou can filter out the symbolic links with the ^ character:
  945. X
  946. X% l *(W^@)
  947. Xrun240
  948. X% l *(x)
  949. Xfoo*        link@       morestuff/  stuff/
  950. X% l *(x^@/)
  951. Xfoo*
  952. X
  953. X
  954. XTo find all plain files, you can use .:
  955. X
  956. X
  957. X
  958. X
  959. X
  960. X
  961. X
  962. X
  963. X
  964. X
  965. X
  966. X
  967. X
  968. X                           - 5 -
  969. X
  970. X% l *(.)
  971. XMakefile  file.h    foo*      foo.o     main.o    run123    run234    run303
  972. Xbar.o     file.pro  foo.c     main.h    q.c       run2      run240    sub
  973. X% l *(^.)
  974. Xlink@       morestuff/  pipe        stuff/
  975. X% l s*(.)
  976. Xstuff/   sub
  977. X% l *(p)
  978. Xpipe
  979. X% l -l *(p)
  980. Xprw-r--r--  1 pfalstad        0 May 23 18:12 pipe
  981. X
  982. X
  983. X*(U) matches all files owned by  you.   To  search  for  all
  984. Xfiles not owned by you, use *(^U):
  985. X
  986. X% l -l *(^U)
  987. X-rw-------  1 subbarao       29 May 23 18:13 sub
  988. X
  989. X
  990. XThis searches for setuid files:
  991. X
  992. X% l -l *(s)
  993. X-rwsr-xr-x  1 pfalstad       16 May 23 18:12 foo*
  994. X
  995. X
  996. XThis checks for a certain user's files:
  997. X
  998. X% ypmatch subbarao passwd
  999. Xsubbarao:*:3338:35:Kartik Subbarao:/u/subbarao:/usr/princeton/bin/zsh
  1000. X% l -l *(u3338)
  1001. X-rw-------  1 subbarao       29 May 23 18:13 sub
  1002. X
  1003. X
  1004. X
  1005. XStartup Files
  1006. X
  1007. XThere are five startup files that  zsh  will  read  commands
  1008. Xfrom:
  1009. X
  1010. X$ZDOTDIR/.zshenv
  1011. X$ZDOTDIR/.zprofile
  1012. X$ZDOTDIR/.zshrc
  1013. X$ZDOTDIR/.zlogin
  1014. X$ZDOTDIR/.zlogout
  1015. X
  1016. X
  1017. XIf ZDOTDIR is not set, then the value of HOME is used;  this
  1018. Xis the usual case.
  1019. X
  1020. X.zshenv is sourced on all invocations of the  shell,  unless
  1021. Xthe -f option is set.  It should contain commands to set the
  1022. Xcommand search path, plus other important environment  vari-
  1023. Xables.   .zshenv  should  not  contain commands that produce
  1024. Xoutput or assume the shell is attached to a tty.
  1025. X
  1026. X.zshrc is sourced in interactive shells.  It should  contain
  1027. Xcommands  to  set  up aliases, functions, options, key bind-
  1028. Xings, etc.
  1029. X
  1030. X
  1031. X
  1032. X
  1033. X
  1034. X                           - 6 -
  1035. X.zlogin is sourced in login shells.  It should contain  com-
  1036. Xmands  that  should be executed only in login shells.  .zlo-
  1037. Xgout is sourced when login shells exit.  .zprofile is  simi-
  1038. Xlar  to  .zlogin,  except  that it is sourced before .zshrc.
  1039. X.zprofile is meant as an  alternative  to  .zlogin  for  ksh
  1040. Xfans; the two are not intended to be used together, although
  1041. Xthis could certainly be done if desired.  .zlogin is not the
  1042. Xplace  for  alias definitions, options, environment variable
  1043. Xsettings, etc.; as a general rule, it should not change  the
  1044. Xshell  environment at all.  Rather, it should be used to set
  1045. Xthe terminal type and run  a  series  of  external  commands
  1046. X(fortune, msgs, etc).
  1047. X
  1048. XShell Functions
  1049. X
  1050. Xzsh also allows you to create your own commands by  defining
  1051. Xshell functions.  For example:
  1052. X
  1053. X% yp () {
  1054. X>       ypmatch $1 passwd.byname
  1055. X> }
  1056. X% yp pfalstad
  1057. Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
  1058. X
  1059. X
  1060. XThis function looks up a user in the NIS password map.   The
  1061. X$1  expands to the first argument to yp.  The function could
  1062. Xhave been equivalently defined in one of the following ways:
  1063. X
  1064. X% function yp {
  1065. X>       ypmatch $1 passwd.byname
  1066. X> }
  1067. X% function yp () {
  1068. X>       ypmatch $1 passwd.byname
  1069. X> }
  1070. X% function yp () ypmatch $1 passwd.byname
  1071. X
  1072. X
  1073. XNote that aliases are expanded when the function  definition
  1074. Xis parsed, not when the function is executed.  For example:
  1075. X
  1076. X% alias ypmatch=echo
  1077. X% yp pfalstad
  1078. Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
  1079. X
  1080. X
  1081. XSince the alias was defined after the function  was  parsed,
  1082. Xit  has  no effect on the function's execution.  However, if
  1083. Xwe define the function again with the alias in place:
  1084. X
  1085. X% function yp () { ypmatch $1 passwd.byname }
  1086. X% yp pfalstad
  1087. Xpfalstad passwd.byname
  1088. X
  1089. X
  1090. Xit is parsed with the new alias definition in place.  There-
  1091. Xfore, in general you must define aliases before functions.
  1092. X
  1093. XWe can make the function take multiple arguments:
  1094. X
  1095. X
  1096. X
  1097. X
  1098. X
  1099. X
  1100. X                           - 7 -
  1101. X
  1102. X% unalias ypmatch
  1103. X% yp () {
  1104. X>       for i
  1105. X>       do ypmatch $i passwd.byname
  1106. X>       done
  1107. X> }
  1108. X% yp pfalstad subbarao sukthnkr
  1109. Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
  1110. Xsubbarao:*:3338:35:Kartik Subbarao:/u/subbarao:/usr/princeton/bin/zsh
  1111. Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
  1112. X
  1113. X
  1114. XThe for i loops through each of  the  function's  arguments,
  1115. Xsetting  i  equal to each of them in turn.  We can also make
  1116. Xthe function do  something  sensible  if  no  arguments  are
  1117. Xgiven:
  1118. X
  1119. X% yp () {
  1120. X>       if (( $# == 0 ))
  1121. X>       then echo usage: yp name ...; fi
  1122. X>       for i; do ypmatch $i passwd.byname; done
  1123. X> }
  1124. X% yp
  1125. Xusage: yp name ...
  1126. X% yp pfalstad sukthnkr
  1127. Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
  1128. Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
  1129. X
  1130. X
  1131. X$# is the number of arguments supplied to the function.   If
  1132. Xit is equal to zero, we print a usage message; otherwise, we
  1133. Xloop through the arguments, and ypmatch all of them.
  1134. X
  1135. XHere's a function that selects a random line from a file:
  1136. X
  1137. X% randline () {
  1138. X>       integer z=$(wc -l <$1)
  1139. X>       sed -n $[RANDOM % z + 1]p $1
  1140. X> }
  1141. X% randline /etc/motd
  1142. XPHOENIX WILL BE DOWN briefly Friday morning, 5/24/91 from 8 AM to
  1143. X% randline /etc/motd
  1144. XSunOS Release 4.1.1 (PHOENIX) #19: Tue May 14 19:03:15 EDT 1991
  1145. X% randline /etc/motd
  1146. X| Please use the "msgs" command to read announcements.  Refer to the   |
  1147. X% echo $z
  1148. X
  1149. X%
  1150. X
  1151. X
  1152. Xrandline has a local variable, z, that holds the  number  of
  1153. Xlines  in  the  file.  $[RANDOM % z + 1] expands to a random
  1154. Xnumber between 1 and z.  An expression of  the  form  $[...]
  1155. Xexpands to the value of the arithmetic expression within the
  1156. Xbrackets, and the RANDOM variable returns  a  random  number
  1157. Xeach  time  it is referenced.  % is the modulus operator, as
  1158. Xin C.  Therefore, sed -n $[RANDOM%z+1]p picks a random  line
  1159. Xfrom its input, from 1 to z.
  1160. X
  1161. X
  1162. X
  1163. X
  1164. X
  1165. X
  1166. X                           - 8 -
  1167. XFunction definitions can be viewed with the functions  buil-
  1168. Xtin:
  1169. X
  1170. X% functions randline
  1171. Xrandline () {
  1172. X        integer z=$(wc -l <$1)
  1173. X        sed -n $[RANDOM % z + 1]p $1
  1174. X
  1175. X}
  1176. X% functions
  1177. Xyp () {
  1178. X        if let $# == 0
  1179. X
  1180. X        then
  1181. X                echo usage: yp name ...
  1182. X
  1183. X        fi
  1184. X        for i
  1185. X        do
  1186. X                ypmatch $i passwd.byname
  1187. X
  1188. X                done
  1189. X
  1190. X}
  1191. Xrandline () {
  1192. X        integer z=$(wc -l <$1)
  1193. X        sed -n $[RANDOM % z + 1]p $1
  1194. X
  1195. X}
  1196. X
  1197. X
  1198. XHere's another one:
  1199. X
  1200. X% cx () { chmod +x $* }
  1201. X% ls -l foo bar
  1202. X-rw-r--r--  1 pfalstad       29 May 24 04:38 bar
  1203. X-rw-r--r--  1 pfalstad       29 May 24 04:38 foo
  1204. X% cx foo bar
  1205. X% ls -l foo bar
  1206. X-rwxr-xr-x  1 pfalstad       29 May 24 04:38 bar
  1207. X-rwxr-xr-x  1 pfalstad       29 May 24 04:38 foo
  1208. X
  1209. X
  1210. XNote that this could also have been implemented as an alias:
  1211. X
  1212. X% chmod 644 foo bar
  1213. X% alias cx='chmod +x'
  1214. X% cx foo bar
  1215. X% ls -l foo bar
  1216. X-rwxr-xr-x  1 pfalstad       29 May 24 04:38 bar
  1217. X-rwxr-xr-x  1 pfalstad       29 May 24 04:38 foo
  1218. X
  1219. X
  1220. X
  1221. XInstead of defining a lot of functions in your  .zshrc,  all
  1222. Xof  which  you  may  not  use, it is often better to use the
  1223. Xautoload builtin.  The idea is, you create a directory where
  1224. Xfunction  definitions  are stored, declare the names in your
  1225. X.zshrc, and tell the shell where to look for them.  Whenever
  1226. Xyou  reference a function, the shell will automatically load
  1227. X
  1228. X
  1229. X
  1230. X
  1231. X
  1232. X                           - 9 -
  1233. Xit into memory.
  1234. X
  1235. X% mkdir /tmp/funs
  1236. X% cat >/tmp/funs/yp
  1237. Xypmatch $1 passwd.byname
  1238. X^D
  1239. X% cat >/tmp/funs/cx
  1240. Xchmod +x $*
  1241. X^D
  1242. X% FPATH=/tmp/funs
  1243. X% autoload cx yp
  1244. X% functions cx yp
  1245. Xundefined cx ()
  1246. Xundefined yp ()
  1247. X% chmod 755 /tmp/funs/{cx,yp}
  1248. X% yp egsirer
  1249. Xegsirer:*:3214:35:Emin Gun Sirer:/u/egsirer:/bin/sh
  1250. X% functions yp
  1251. Xyp () {
  1252. X        ypmatch $1 passwd.byname
  1253. X}
  1254. X
  1255. X
  1256. XThis idea has other benefits.  By adding a #! header to  the
  1257. Xfiles, you can make them double as shell scripts.  (Although
  1258. Xit is faster to use them as functions, since a separate pro-
  1259. Xcess is not created.)
  1260. X
  1261. X% ed /tmp/funs/yp
  1262. X25
  1263. Xi
  1264. X#! /usr/local/bin/zsh
  1265. Xw
  1266. X42
  1267. Xq
  1268. X% </tmp/funs/yp
  1269. X#! /usr/local/bin/zsh
  1270. Xypmatch $1 passwd.byname
  1271. X% /tmp/funs/yp sukthnkr
  1272. Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
  1273. X
  1274. X
  1275. XNow other people, who may not use zsh, or who don't want  to
  1276. Xcopy  all  of  your .zshrc, may use these functions as shell
  1277. Xscripts.
  1278. X
  1279. XDirectories
  1280. X
  1281. XOne nice feature of zsh is the way  it  prints  directories.
  1282. XFor example, if we set the prompt like this:
  1283. X
  1284. Xphoenix% PROMPT='%~> '
  1285. X~> cd src
  1286. X~/src>
  1287. X
  1288. X
  1289. Xthe shell will print the current directory  in  the  prompt,
  1290. Xusing  the  ~  character.  However, zsh is smarter than most
  1291. Xother shells in this respect:
  1292. X
  1293. X
  1294. X
  1295. X
  1296. X
  1297. X
  1298. X                           - 10 -
  1299. X
  1300. X~/src> cd ~subbarao
  1301. X~subbarao> cd ~maruchck
  1302. X~maruchck> cd lib
  1303. X~maruchck/lib> cd fun
  1304. X~maruchck/lib/fun> foo=/usr/princeton/common/src
  1305. X~maruchck/lib/fun> cd ~foo
  1306. X~foo> cd ..
  1307. X/usr/princeton/common> cd src
  1308. X~foo> cd news/nntp
  1309. X~foo/news/nntp> cd inews
  1310. X~foo/news/nntp/inews>
  1311. X
  1312. X
  1313. XNote that zsh prints other users' directories  in  the  form
  1314. X~user.  Also note that you can set a parameter and use it as
  1315. Xa directory name; zsh will act as if foo is a user with  the
  1316. Xlogin  directory  /usr/princeton/common/src.   This  is con-
  1317. Xvenient, especially if you're sick of  seeing  prompts  like
  1318. Xthis:
  1319. X
  1320. Xphoenix:/usr/princeton/common/src/X.V11R4/contrib/clients/xv/docs>
  1321. X
  1322. X
  1323. XIf you get stuck in this position, you can give the  current
  1324. Xdirectory a short name, like this:
  1325. X
  1326. X/usr/princeton/common/src/news/nntp/inews> inews=$PWD
  1327. X/usr/princeton/common/src/news/nntp/inews> echo ~inews
  1328. X/usr/princeton/common/src/news/nntp/inews
  1329. X~inews>
  1330. X
  1331. X
  1332. XWhen you reference a directory in the form ~inews, the shell
  1333. Xassumes  that you want the directory displayed in this form;
  1334. Xthus simply typing echo  ~inews  or  cd  ~inews  causes  the
  1335. Xprompt to be shortened.  You can define a shell function for
  1336. Xthis purpose:
  1337. X
  1338. X~inews> namedir () { $1=$PWD ;  : ~$1 }
  1339. X~inews> cd /usr/princeton/bin
  1340. X/usr/princeton/bin> namedir pbin
  1341. X~pbin> cd /var/spool/mail
  1342. X/var/spool/mail> namedir spool
  1343. X~spool> cd .msgs
  1344. X~spool/.msgs>
  1345. X
  1346. X
  1347. XYou may want to add this one-line function to your .zshrc.
  1348. X
  1349. Xzsh can also put the current directory in your title bar, if
  1350. Xyou  are  using  a  windowing system.  One way to do this is
  1351. Xwith the chpwd function, which is automatically executed  by
  1352. Xthe  shell  whenever you change directory.  If you are using
  1353. Xxterm, this will work:
  1354. X
  1355. Xchpwd () { print -Pn '^[]2;%~^G' }
  1356. X
  1357. X
  1358. XThe -P option tells print to  treat  its  arguments  like  a
  1359. X
  1360. X
  1361. X
  1362. X
  1363. X
  1364. X                           - 11 -
  1365. Xprompt  string; otherwise the %~ would not be expanded.  The
  1366. X-n option suppresses the terminating newline, as with echo.
  1367. X
  1368. XIf you are using an IRIS wsh, do this:
  1369. X
  1370. Xchpwd () { print -Pn '^[P1.y%~^[' }
  1371. X
  1372. X
  1373. XThe print -D command has other uses.  For example, to  print
  1374. Xthe  current directory to standard output in short form, you
  1375. Xcan do this:
  1376. X
  1377. X% print -D $PWD
  1378. X~subbarao/src
  1379. X
  1380. X
  1381. Xand to print each component of the path in short form:
  1382. X
  1383. X% print -D $path
  1384. X/bin /usr/bin ~locbin ~locbin/X11 ~/bin
  1385. X
  1386. X
  1387. X
  1388. XDirectory Stacks
  1389. X
  1390. XIf you use csh, you may know about  directory  stacks.   The
  1391. Xpushd  command  puts the current directory on the stack, and
  1392. Xchanges to a new directory; the popd command pops  a  direc-
  1393. Xtory off the stack and changes to it.
  1394. X
  1395. Xphoenix% cd
  1396. Xphoenix% PROMPT='Z %~> '
  1397. XZ ~> pushd /tmp
  1398. X/tmp ~
  1399. XZ /tmp> pushd /usr/etc
  1400. X/usr/etc /tmp ~
  1401. XZ /usr/etc> pushd /usr/bin
  1402. X/usr/bin /usr/etc /tmp ~
  1403. XZ /usr/bin> popd
  1404. X/usr/etc /tmp ~
  1405. XZ /usr/etc> popd
  1406. X/tmp ~
  1407. XZ /tmp> pushd /etc
  1408. X/etc /tmp ~
  1409. XZ /etc> popd
  1410. X/tmp ~
  1411. X
  1412. X
  1413. Xzsh's directory stack commands work similarly.  One  differ-
  1414. Xence  is the way pushd is handled if no arguments are given.
  1415. XAs in csh, this exchanges the top two elements of the direc-
  1416. Xtory stack:
  1417. X
  1418. XZ /tmp> dirs
  1419. X/tmp ~
  1420. XZ /tmp> pushd
  1421. X~ /tmp
  1422. X
  1423. X
  1424. Xunless the stack only has one entry:
  1425. X
  1426. X
  1427. X
  1428. X
  1429. X
  1430. X                           - 12 -
  1431. X
  1432. XZ ~> popd
  1433. X/tmp
  1434. XZ /tmp> dirs
  1435. X/tmp
  1436. XZ /tmp> pushd
  1437. X~ /tmp
  1438. X
  1439. X
  1440. Xor unless the PUSHDTOHOME option is set:
  1441. X
  1442. XZ ~> setopt pushdtohome
  1443. XZ ~> pushd
  1444. X~ ~ /tmp
  1445. X
  1446. X
  1447. X
  1448. XAs an alternative to using directory stacks in this  manner,
  1449. Xwe  can  get something like a directory history by setting a
  1450. Xfew more options and parameters:
  1451. X
  1452. X~> DIRSTACKSIZE=8
  1453. X~> setopt autopushd pushdminus pushdsilent pushdtohome
  1454. X~> alias dh='dirs -v'
  1455. X~> cd /tmp
  1456. X/tmp> cd /usr
  1457. X/usr> cd bin
  1458. X/usr/bin> cd ../pub
  1459. X/usr/pub> dh
  1460. X0       /usr/pub
  1461. X1       /usr/bin
  1462. X2       /usr
  1463. X3       /tmp
  1464. X4       ~
  1465. X/usr/pub> cd -3
  1466. X/tmp> dh
  1467. X0       /tmp
  1468. X1       /usr/pub
  1469. X2       /usr/bin
  1470. X3       /usr
  1471. X4       ~
  1472. X/tmp> ls =2/df
  1473. X/usr/bin/df
  1474. X/tmp> cd -4
  1475. X~>
  1476. X
  1477. X
  1478. XNote that =2 expanded to the second directory in the history
  1479. Xlist,  and  that  cd  -3 recalled the third directory in the
  1480. Xlist.
  1481. X
  1482. XYou may be wondering what all those options  do.   AUTOPUSHD
  1483. Xmade  cd act like pushd.  (alias cd=pushd is not sufficient,
  1484. Xfor various reasons.) PUSHDMINUS swapped the meaning  of  cd
  1485. X+1 and cd -1; we want them to mean the opposite of what they
  1486. Xmean in csh, because it makes more sense in this scheme, and
  1487. Xit's easier to type:
  1488. X
  1489. X
  1490. X
  1491. X
  1492. X
  1493. X
  1494. X
  1495. X
  1496. X                           - 13 -
  1497. X
  1498. X~> dh
  1499. X0       ~
  1500. X1       /tmp
  1501. X2       /usr/pub
  1502. X3       /usr/bin
  1503. X4       /usr
  1504. X~> unsetopt pushdminus
  1505. X~> cd +1
  1506. X/tmp> dh
  1507. X0       /tmp
  1508. X1       ~
  1509. X2       /usr/pub
  1510. X3       /usr/bin
  1511. X4       /usr
  1512. X/tmp> cd +2
  1513. X/usr/pub>
  1514. X
  1515. X
  1516. XPUSHDSILENT keeps the  shell  from  printing  the  directory
  1517. Xstack  each  time  we  do a cd, and PUSHDTOHOME we mentioned
  1518. Xearlier:
  1519. X
  1520. X/usr/pub> unsetopt pushdsilent
  1521. X/usr/pub> cd /etc
  1522. X/etc /usr/pub /tmp ~ /usr/bin /usr
  1523. X/etc> cd
  1524. X~ /etc /usr/pub /tmp ~ /usr/bin /usr
  1525. X~> unsetopt pushdtohome
  1526. X~> cd
  1527. X/etc ~ /usr/pub /tmp ~ /usr/bin /usr
  1528. X/etc>
  1529. X
  1530. X
  1531. XDIRSTACKSIZE keeps the  directory  stack  from  getting  too
  1532. Xlarge, much like HISTSIZE:
  1533. X
  1534. X/etc> setopt pushdsilent
  1535. X/etc> cd /
  1536. X/> cd /
  1537. X/> cd /
  1538. X/> cd /
  1539. X/> cd /
  1540. X/> cd /
  1541. X/> cd /
  1542. X/> cd /
  1543. X/> dh
  1544. X0       /
  1545. X1       /
  1546. X2       /
  1547. X3       /
  1548. X4       /
  1549. X5       /
  1550. X6       /
  1551. X7       /
  1552. X
  1553. X
  1554. X
  1555. X
  1556. X
  1557. X
  1558. X
  1559. X
  1560. X
  1561. X
  1562. X                           - 14 -
  1563. XCommand/Process Substitution
  1564. X
  1565. XCommand substitution in zsh can  take  two  forms.   In  the
  1566. Xtraditional  form,  a command enclosed in backquotes (`...`)
  1567. Xis replaced on the command line with its  output.   This  is
  1568. Xthe  form used by the older shells.  Newer shells (like zsh)
  1569. Xalso provide another form, $(...).  This form is much easier
  1570. Xto nest.
  1571. X
  1572. X% ls -l `echo /vmunix`
  1573. X-rwxr-xr-x  1 root      1209702 May 14 19:04 /vmunix
  1574. X% ls -l $(echo /vmunix)
  1575. X-rwxr-xr-x  1 root      1209702 May 14 19:04 /vmunix
  1576. X% who | grep mad
  1577. Xsubbarao ttyt7   May 23 15:02   (mad55sx15.Prince)
  1578. Xpfalstad ttyu1   May 23 16:25   (mad55sx14.Prince)
  1579. Xsubbarao ttyu6   May 23 15:04   (mad55sx15.Prince)
  1580. Xpfalstad ttyv3   May 23 16:25   (mad55sx14.Prince)
  1581. X% who | grep mad | awk '{print $2}'
  1582. Xttyt7
  1583. Xttyu1
  1584. Xttyu6
  1585. Xttyv3
  1586. X% cd /dev; ls -l $(who |
  1587. X> grep $(echo mad) |
  1588. X> awk '{ print $2 }')
  1589. Xcrwx-w----  1 subbarao  20,  71 May 23 18:35 ttyt7
  1590. Xcrw--w----  1 pfalstad  20,  81 May 23 18:42 ttyu1
  1591. Xcrwx-w----  1 subbarao  20,  86 May 23 18:38 ttyu6
  1592. Xcrw--w----  1 pfalstad  20,  99 May 23 18:41 ttyv3
  1593. X
  1594. X
  1595. XMany common  uses  of  command  substitution,  however,  are
  1596. Xsuperseded by other mechanisms of zsh:
  1597. X
  1598. X% ls -l `tty`
  1599. Xcrw-rw-rw-  1 root      20,  28 May 23 18:35 /dev/ttyqc
  1600. X% ls -l $TTY
  1601. Xcrw-rw-rw-  1 root      20,  28 May 23 18:35 /dev/ttyqc
  1602. X% ls -l `which rn`
  1603. X-rwxr-xr-x  1 root       172032 Mar  6 18:40 /usr/princeton/bin/rn
  1604. X% ls -l =rn
  1605. X-rwxr-xr-x  1 root       172032 Mar  6 18:40 /usr/princeton/bin/rn
  1606. X
  1607. X
  1608. XA command name with a = prepended is replaced with its  full
  1609. Xpathname.   This  can  be very convenient.  If it's not con-
  1610. Xvenient for you, you can turn it off:
  1611. X
  1612. X% ls
  1613. X=foo    =bar
  1614. X% ls =foo =bar
  1615. Xzsh: foo not found
  1616. X% setopt noequals
  1617. X% ls =foo =bar
  1618. X=foo    =bar
  1619. X
  1620. X
  1621. X
  1622. XAnother nice feature is process substitution:
  1623. X
  1624. X
  1625. X
  1626. X
  1627. X
  1628. X                           - 15 -
  1629. X
  1630. X% who | fgrep -f =(print -l root lemke shgchan subbarao)
  1631. Xroot     console May 19 10:41
  1632. Xlemke    ttyq0   May 22 10:05   (narnia:0.0)
  1633. Xlemke    ttyr7   May 22 10:05   (narnia:0.0)
  1634. Xlemke    ttyrd   May 22 10:05   (narnia:0.0)
  1635. Xshgchan  ttys1   May 23 16:52   (gaudi.Princeton.)
  1636. Xsubbarao ttyt7   May 23 15:02   (mad55sx15.Prince)
  1637. Xsubbarao ttyu6   May 23 15:04   (mad55sx15.Prince)
  1638. Xshgchan  ttyvb   May 23 16:51   (gaudi.Princeton.)
  1639. X
  1640. X
  1641. XA command of the form =(...) is replaced with the name of  a
  1642. Xfile containing its output.  (A command substitution, on the
  1643. SHAR_EOF
  1644. true || echo 'restore of zsh2.2/doc/intro.txt failed'
  1645. fi
  1646. echo 'End of zsh2.2 part 1'
  1647. echo 'File zsh2.2/doc/intro.txt is continued in part 2'
  1648. echo 2 > _shar_seq_.tmp
  1649. exit 0
  1650.  
  1651. exit 0 # Just in case...
  1652.